#define _CRT_SECURE_NO_WARNINGS 1







class Solution {
public:
    string countAndSay(int n) {
        string ret = "1";
        int count = 0;
        for (int i = 1; i < n; i++)
        {
            string tmp;
            int len = ret.size();
            for (int left = 0, right = 0; right < len; )
            {
                int count = 0;
                while (right < len && ret[left] == ret[right])
                {
                    right++;
                    count++;
                }
                tmp += to_string(count) + ret[left];
                left = right;
            }
            ret = tmp;
        }
        return ret;
    }
};